<template>
    <div class="login-container">
        <div class="login-left">
            <img src="../assets/imgs/login_img.png">
        </div>
        <div class="login-box">
            <div class="avatar-box">
                <img src="../assets/imgs/login_logo.png">
            </div>
            <div class="title">
                服务器巡检
            </div>
            <el-form ref="LoginFormRef" :model="LoginForm" :rules="rules" class="login-form">
                <el-form-item prop="username">
                    <el-input placeholder="请输入用户名" prefix-icon="iconfont icon-user" v-model="LoginForm.username"></el-input>
                </el-form-item>
                <el-form-item prop="password">
                    <el-input placeholder="请输入密码" prefix-icon="iconfont icon-lock_fill" show-password v-model="LoginForm.password"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" class="login-button" @click="login">登录</el-button>
                </el-form-item>
            </el-form>

        </div>
    </div>
</template>
  
<script>

export default {
    data() {
        return {
            LoginForm:{
            username:'admin',
            password:'123456'
            },
            rules: {
            username: [
                { required: true, message: '请输入用户名', trigger: 'blur' },
                { min: 3, max: 7, message: '长度在 3 到 5 个字符', trigger: 'blur' }
            ],
            password: [
                { required: true, message: '请输入登陆密码', trigger: 'blur' },
                { min: 1, max: 6, message: '长度在 1 到 6 个字符', trigger: 'blur' }
            ]
            }
        }
    },
    methods: {
         login(){
            // this.$refs.LoginFormRef.validate(async valid => {
            //     if(!valid){
            //         console.log('valid',valid)
            //         return 
            //     }
            this.$http.post('/login/',this.LoginForm).then( res => {
                console.log('login res', res.data)
                if(typeof(res.data) === 'string'){
                    return this.$message.warning(res.data);
                }
                if(res.data.meta.status !== 200){
                    return this.$message.error(res.data.meta.msg)
                }
                this.$message.success('登陆成功')
                sessionStorage.setItem('userInfo',JSON.stringify(res.data.data))
                console.log('userInfo login', sessionStorage.getItem('userInfo'))
                this.$router.push('/home/')
                })
            // })
        }
    },
}
</script>

<style lang="less" scoped>
.login-container{
    background-color: #93defe;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}
.login-left{
    margin-right: 100px;
}
.login-box{
    width: 400px;
    height: 350px;
    background-color: #fff;
    border-radius: 6px;
    padding: 50px;
    box-sizing: border-box;
    position: relative;
}
.avatar-box{
    width: 120px;
    height: 120px;
    border: 5px solid #93defe;
    border-radius: 50%;
    text-align: center;
    line-height: 110px;
    position: absolute;
    top:-60px;
    left: 140px;
    background-color: #fff;
}
.title{
    position: absolute;
    top: 100px;
    left: 50%;
    transform: translate(-50%);
    font-size: 18px;
    color: #444;
}
.login-form{
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translate(-50%);
    width: 80%;
    padding: 0 20px;
    box-sizing: border-box;
    .login-button{
        width: 100%;
    }
}
</style>
